package com.karst87.study.dowithbytes.chapter01
{
	import com.karst87.study.dowithbytes.utils.BytesUtils;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import org.aswing.Container;
	import org.aswing.EmptyLayout;
	import org.aswing.FlowLayout;
	import org.aswing.JButton;
	import org.aswing.JComboBox;
	import org.aswing.JPanel;
	import org.aswing.JTextField;

	internal class ByteStudy extends JPanel
	{
		public function ByteStudy()
		{
			super( new EmptyLayout() ) ;
			createView() ;
		}

		private var numTF : JTextField = null ;
		private var typeComb : JComboBox = null ;
		private var executeBtn : JButton = null ;
		private function createView() : void
		{
			if( numTF == null )
				numTF = new JTextField( "0" ) ;
			numTF.setSizeWH( 240, 25 ) ;
			numTF.setLocationXY( 10 , 5 ) ;
			
			if( typeComb == null )
				typeComb = new JComboBox() ;
			typeComb.setSizeWH( 40, 25 ) ;
			typeComb.setLocationXY( 260 , 5 ) ;
			typeComb.setListData( [2, 8, 10, 16] ) ;
			typeComb.setSelectedIndex( 2 ) ;
			
			if( executeBtn == null )
				executeBtn = new JButton( "Execute" ) ;
			executeBtn.setSizeWH( 60, 25 ) ;
			executeBtn.setLocationXY( 310 , 5 ) ;
			executeBtn.addEventListener( MouseEvent.CLICK, executeHandler ) ;
			
			appendAll( numTF, typeComb,  executeBtn ) ;
		}

		private var preType : uint = 10 ;
		private function executeHandler( $event : MouseEvent = null ) : void
		{
			numTF.setText( BytesUtils.covertBinary(numTF.getText(), preType ).toString( typeComb.getSelectedItem() ) ) ;
			preType = typeComb.getSelectedItem() ;
		}
	}
}